import 'package:app/pages/index/index_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import '../../shared/constants/common.dart';
import '../../components/customanimateBottomBar.dart';

class IndexPage extends GetView<IndexController> {
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Obx(() => _buildWidget()), onWillPop: () async => false);
  }

  Widget _buildWidget() {
    return Scaffold(
      backgroundColor: Colors.white,
      body: PageView(
        controller: controller.pageController,
        children: [
          controller.homeTab,
          controller.discoverTab,
          Container(),
          controller.messageTab,
          controller.meTab
        ],
      ),
      bottomNavigationBar: CustomAnimatedBottomBar(
        showElevation: true,
        selectedIndex: controller.getCurrentIndex(controller.currentTab.value),
        backgroundColor: Colors.white,
        containerHeight: 86,
        onTiemSelected: (index) {
          controller.currentIndex = index;
          controller.pageController.jumpToPage(controller.currentIndex);
          controller.switchTab(index);
        },
        items: <MyBottomNaviationBarItem>[
          MyBottomNaviationBarItem(
            activeIcon: SvgPicture.asset(
              'assets/icons/home_active.svg',
              height: 24,
            ),
            inactiveIcon:
                SvgPicture.asset('assets/icons/home_inactive.svg', height: 24),
            title: Text("首页"),
            activeColor: sTextColor,
            inactiveColor: sTextColorDes,
            textAlign: TextAlign.center,
          ),
          MyBottomNaviationBarItem(
            activeIcon: SvgPicture.asset('assets/icons/discover_active.svg',
                height: 34),
            inactiveIcon: SvgPicture.asset('assets/icons/discover_inactive.svg',
                height: 34),
            title: Text("发现"),
            activeColor: sTextColor,
            inactiveColor: sTextColorDes,
            textAlign: TextAlign.center,
          ),
          MyBottomNaviationBarItem(
            activeIcon: Image.asset(
              'assets/icons/add.png',
              height: 46,
            ),
            inactiveIcon: Image.asset('assets/icons/add.png', height: 46),
            title: Text(""),
            showText: false,
            activeColor: sTextColor,
            inactiveColor: sTextColorDes,
            textAlign: TextAlign.center,
          ),
          MyBottomNaviationBarItem(
            activeIcon:
                SvgPicture.asset('assets/icons/message_active.svg', height: 26),
            inactiveIcon: SvgPicture.asset('assets/icons/message_inactive.svg',
                height: 26),
            title: Text("消息"),
            activeColor: sTextColor,
            inactiveColor: sTextColorDes,
            textAlign: TextAlign.center,
          ),
          MyBottomNaviationBarItem(
            activeIcon:
                SvgPicture.asset('assets/icons/me_active.svg', height: 26),
            inactiveIcon:
                SvgPicture.asset('assets/icons/me_inactive.svg', height: 26),
            title: Text("我的"),
            activeColor: sTextColor,
            inactiveColor: sTextColorDes,
            textAlign: TextAlign.center,
          ),
        ],
      ),
    );
  }

  // Widget _buildContent(MainTabs tab) {
  //   switch (tab) {
  //     case MainTabs.home:
  //       return controller.homeTab;
  //     case MainTabs.discover:
  //       return controller.discoverTab;
  //     case MainTabs.message:
  //       return controller.messageTab;
  //     case MainTabs.me:
  //       return controller.meTab;
  //     default:
  //       return controller.homeTab;
  //   }
  // }
}
